/**
 * 
 */
package com.taobao.api.model;

import java.io.Serializable;

import com.taobao.api.util.EncodeUtil;

/**
 * 调用Top的API返回的response ErrorCode错误码 body 响应的body部分 redirectUrl 绑定用户所需重定向URL
 * body 响应的body部分
 * 
 * @author sulinchong.pt
 * 
 */
public class UrlResponse implements Serializable{
	private static final long serialVersionUID = 5014379068811962022L;
	
	private String errorCode;
	private String msg;
	private String redirectUrl;
	private String body;

	public UrlResponse() {
		super();
	}

	public UrlResponse(String body, String errorCode, String msg,
			String redirectUrl) {
		super();
		this.body = body;
		this.errorCode = errorCode;
		this.msg = msg;
		this.redirectUrl = redirectUrl;
	}

	public UrlResponse(UrlResponse rsp) {
		this(rsp.body, rsp.errorCode, rsp.msg, rsp.redirectUrl);
	}

	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * 判断是否调用API成功
	 * 
	 * @return 如果成功,返回true
	 */
	public boolean isSuccess() {
		return null == errorCode;
	}

	public boolean isRedirect() {
		return null != redirectUrl;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	/**
	 * 得到绑定用户需要重定向的URL
	 * 
	 * @return
	 */
	public String getRedirectUrl() {
		return redirectUrl;
	}

	/**
	 * 得到绑定用户需要重定向的URL
	 * 
	 * @param target
	 *            绑定用户成功后重定向的目标地址
	 * @return
	 */
	public String getRedirectUrl(String target) {
		return redirectUrl + "&sip_redirecturl=" + target;
	}

	/**
	 * 得到绑定用户需要重定向的URL，对绑定后重定向回isv的url做urlEncode编码
	 * 
	 * @param target
	 * @return
	 */
	public String getEncodedRedirectUrl(String target) {
		return redirectUrl + "&sip_redirecturl=" + EncodeUtil.encodeUrl(target);
	}

	public void setRedirectUrl(String redirectUrl) {
		this.redirectUrl = redirectUrl;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}
}
